﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using QuanLyBus.Model;
using testSMS;
namespace QuanLyBus
{
    public partial class Them_tram_dung : PhoneApplicationPage
    {
        QL_TuyenDataContext db = new QL_TuyenDataContext(App.constr);
        classGoTV gotvTxtBody = new classGoTV();//tao đối tượng
        public Them_tram_dung()
        {
            InitializeComponent();
        }
        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            this.NavigationService.GoBack();
            base.OnBackKeyPress(e);
        }

        private void btn_add_Click(object sender, EventArgs e)
        {
            string so_nha_txt, duong_txt, quan_txt;
            so_nha_txt=txt_so_nha.Text;
            duong_txt = txt_duong.Text;
            quan_txt = txt_quan.Text;
            db.ds_trams.InsertOnSubmit(new ds_tram() {so_nha=so_nha_txt,duong=duong_txt,quan=quan_txt });
            db.SubmitChanges();
            MessageBox.Show("Thêm Thành Công");
            this.NavigationService.Navigate(new Uri("/Them_tram_thuoc_tuyen.xaml", UriKind.Relative));
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.NavigationService.GoBack();
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            txt_so_nha.AddHandler(TextBox.KeyDownEvent, new KeyEventHandler(txt_so_nha_KeyDown), true);
            txt_duong.AddHandler(TextBox.KeyDownEvent, new KeyEventHandler(txt_duong_KeyDown), true);
            txt_quan.AddHandler(TextBox.KeyDownEvent, new KeyEventHandler(txt_quan_KeyDown), true);
        }

        private void txt_so_nha_KeyDown(object sender, KeyEventArgs e)
        {
            TextBox t = sender as TextBox;

            if (e.Key == Key.Back)

                gotvTxtBody.XoaKtu = true;

            else

            {

                if (e.Key == Key.Space)

                {

                    gotvTxtBody.NhapSpace = true;
                    gotvTxtBody.CoNguyenAm = false;

                }

            }

        }

        private void txt_so_nha_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (gotvTxtBody.TextChanged == 2)

            {

                gotvTxtBody.TextChanged = 0;

                gotvTxtBody.GoDauTV(ref txt_so_nha);

            }

            gotvTxtBody.TextChanged++;

                }

        private void txt_duong_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (gotvTxtBody.TextChanged == 2)

            {

                gotvTxtBody.TextChanged = 0;

                gotvTxtBody.GoDauTV(ref txt_duong);

            }

            gotvTxtBody.TextChanged++;

        }

        private void txt_duong_KeyDown(object sender, KeyEventArgs e)
        {
            TextBox t = sender as TextBox;

            if (e.Key == Key.Back)

                gotvTxtBody.XoaKtu = true;

            else

            {

                if (e.Key == Key.Space)

                {

                    gotvTxtBody.NhapSpace = true;
                    gotvTxtBody.CoNguyenAm = false;

                }

            }
        }

        private void txt_quan_KeyDown(object sender, KeyEventArgs e)
        {
            TextBox t = sender as TextBox;

            if (e.Key == Key.Back)

                gotvTxtBody.XoaKtu = true;

            else
            {

                if (e.Key == Key.Space)
                {

                    gotvTxtBody.NhapSpace = true;
                    gotvTxtBody.CoNguyenAm = false;

                }

            }
        }

        private void txt_quan_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (gotvTxtBody.TextChanged == 2)
            {

                gotvTxtBody.TextChanged = 0;

                gotvTxtBody.GoDauTV(ref txt_quan);

            }

            gotvTxtBody.TextChanged++;
        }
        

        
    }
}